<?php
/**
 * Parcl
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://parcl.com/license
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@parcl.com so we can send you a copy immediately.
 *
 * @category parcl
 * @package parcl-core
 * @copyright Copyright (c) 2006-2011 Mikael Knutsson (http://mikn.me)
 * @license http://parcl.com/license New BSD License
 * 
 * @author mikael
 */

namespace Parcl\Core {

	if(PARCL_EXEC !== 1) {
		die('<h1>Incorrect Access</h1>You cannot access this file directly.<br/>' .
			 'If you got this error message by clicking a link on the site,' .
			 'please notify the webmaster as soon as possible.');
	}

	/**
	 * Purpose     : A container for all events that you can trigger.
	 * Description : Specifies all triggerable events, this is later going to be a
					 registry for events where modules can add their own events
					 at startup. That is the reason it is specified as a singleton.
	 * - Construct -
	 * Not specified.
	 */

	class RegisterEvents implements ISingleton {
		private static $instance = null;

		public static function GetInstance() {
			if(is_null(self::$instance)) {
				self::$instance = new RegisterEvents();
			}
			return self::$instance;
		}

		private function __construct() {
		}

		/**
		 * Input       : $events: The instance of EventCollection. Enforced through type hinting.
		 * Output      : None.
		 * Description : Adds all general events available within Parcl.
		 * Errors      : No error conditions have been defined.
		 * Assumptions : None.
		 * Dev Notes   : Thought this was a pretty good way of adding all the triggerable
						 events to make sure that they are indeed legal.
		 */

		public function AddGeneralEvents(EventCollection $events) {
			$events->Add(new Event('L:MESSAGE_RECEIVED'), false);
			$events->Add(new Event('P:STARTUP'));
			$events->Add(new Event('P:LAYOUT_LOADED'));
			$events->Add(new Event('P:MODULE_LOADING'), false);
			$events->Add(new Event('P:CONTENT_LOADED'));
			$events->Add(new Event('P:PARCELS_LOADED'));
			$events->Add(new Event('P:PAGE_PREPARED'));
			$events->Add(new Event('P:PAGE_GENERATED'));
			$events->Add(new Event('P:SHUTDOWN'));
		}

		public function AddDbEvents(EventCollection &$events) {
			$events->Add(new Event('DB:CONNECTED'));
			$events->Add(new Event('DB:QUERY_RECEIVED'), false);
			$events->Add(new Event('DB:QUERY_PREPARED'), false);
			$events->Add(new Event('DB:PARAMS_SET'), false);
			$events->Add(new Event('DB:PARAMS_BOUND'), false);
			$events->Add(new Event('DB:EXECUTION_MADE'), false);
			$events->Add(new Event('DB:FETCH_RESULT'), false);
			$events->Add(new Event('DB:RESULT_GENERATED'), false);
		}

		/***
		 * Locks the EventCollection when you unset RegisterEvents.
		 */

		public function __destruct() {
			EventCollection::Lock();
		}
	}
}